package com.yang.controller.data;

import com.yang.service.CategoryService;
import com.yang.utils.ThreadLocalUtil;
import com.yang.vo.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags = "分类模块")
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @ApiOperation("获取所有分类")
    @GetMapping("/list")
    public ResponseResult getCategoryList(){
        log.info("id为{}的用户获取所有分类", ThreadLocalUtil.get());
        return ResponseResult.success(categoryService.list());
    }

    @ApiOperation("根据分类统计月收入、支出")
    @GetMapping("/month_statistic")
    public ResponseResult getMonthStatistic(@RequestParam("categoryId") Long categoryId,
                                            @RequestParam("month")Integer month){
        log.info("id为{}的用户获取了id为{}的分类{}月份的总收入、总支出",
                ThreadLocalUtil.get(),categoryId,month);
        return categoryService.getMonthStatistic(categoryId,month);
    }

}
